package com.midian.model.activity;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.midian.common.utils.StringUtil;
import com.midian.model.common.BaseModel;
import com.midian.model.organization.Organization;
import com.midian.model.pic.Pic;
import com.midian.service.activity.IActivityService;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Type;

import com.vividsolutions.jts.geom.Point;

/**
 * 活动
 * 
 */
@Entity
@Table(name = "activity")
public class Activity extends BaseModel {
//	/**封面图片id*/
//	private String coverPicId;
	/**活动标题*/
	private String title;
//	/**机构id*/
//	private String organizationId;
//	/**活动类型id*/
//	private String typeId;
	/**大人价格*/
	private Double adultPrice;
	/**小孩价格*/
	private Double childPrice;
	/**活动适合的小孩年龄,多个用逗号隔开*/
	private String ages;
	/**活动开始时间*/
	@Temporal(TemporalType.TIMESTAMP)
	private Date beginTime;
	/**后台先用String类型接收时间数据在做转换*/
	@Transient
	private String beginTimeString;
	/**联系人姓名*/
	private String contactPerson;
	/**联系人号码*/
	private String contactNum;
	/**联系地址*/
	private String contactAddress;
	/**联系位置*/
	@Type(type = "org.hibernatespatial.GeometryUserType")
	private Point contactAddressLocation;
	/**联系位置经度*/
	private Double contactAddressLon;
	/**联系位置纬度*/
	private Double contactAddressLat;
	/**活动地址*/
	private String activityAddress;
	/**活动地址位置*/
	@Type(type = "org.hibernatespatial.GeometryUserType")
	private Point activityAddressLocation;
	/**活动地址经度*/
	private Double activityAddressLon;
	/**活动地址纬度*/
	private Double activityAddressLat;
	/**活动详情*/
	private String detail;
	/**已报名人数*/
	private Integer joinCount;
	/**限制报名人数*/
	private Integer joinLimitCount;
	/**省id*/
	private String provinceId;
	/**城市id*/
	private String cityId;
	/**区id*/
	private String areaId;
	/**街道id*/
	private String streetId;
	/**大人是否需要计数 1需要  0不需要*/
	private Integer isAdultRecord;
	/**机构实体对象*/
	@ManyToOne(optional=true,fetch=FetchType.LAZY)
	@JoinColumn(name="organizationId")
	@NotFound(action=NotFoundAction.IGNORE)
	private Organization organization;
	@ManyToOne(optional=true,fetch=FetchType.LAZY)
	@JoinColumn(name="typeId")
	@NotFound(action=NotFoundAction.IGNORE)
	private ActivityType activityType;
	@ManyToOne(optional=true,fetch=FetchType.LAZY)
	@JoinColumn(name="coverPicId")
	@NotFound(action=NotFoundAction.IGNORE)
	private Pic coverPic;
	
	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}
	
	public String getTitle() {
		return title;
	}
	
	@Transient
	public String getBeginTimeString() {
		return beginTimeString;
	}

	public void setBeginTimeString(String beginTimeString) {
		this.beginTimeString = beginTimeString;
	}

	public void setTitle(String title) {
		this.title = title;
	}


	public ActivityType getActivityType() {
		return activityType;
	}

	
	public Integer getIsAdultRecord() {
		return isAdultRecord;
	}

	public void setIsAdultRecord(Integer isAdultRecord) {
		this.isAdultRecord = isAdultRecord;
	}

	public void setActivityType(ActivityType activityType) {
		this.activityType = activityType;
	}

	public Pic getCoverPic() {
		return coverPic;
	}

	public void setCoverPic(Pic coverPic) {
		this.coverPic = coverPic;
	}

	public Double getAdultPrice() {
		return adultPrice;
	}

	public void setAdultPrice(Double adultPrice) {
		this.adultPrice = adultPrice;
	}

	public Double getChildPrice() {
		return childPrice;
	}

	public void setChildPrice(Double childPrice) {
		this.childPrice = childPrice;
	}

	public String getAges() {
		return ages;
	}

	public void setAges(String ages) {
		this.ages = ages;
	}
	
	@JSON(format = "yyyy-MM-dd HH:mm")
	public Date getBeginTime() {
		return beginTime;
	}

	public void setBeginTime(Date beginTime) {
		this.beginTime = beginTime;
	}

	public String getContactPerson() {
		return contactPerson;
	}

	public void setContactPerson(String contactPerson) {
		this.contactPerson = contactPerson;
	}

	public String getContactNum() {
		return contactNum;
	}

	public void setContactNum(String contactNum) {
		this.contactNum = contactNum;
	}

	public String getContactAddress() {
		return contactAddress;
	}

	public void setContactAddress(String contactAddress) {
		this.contactAddress = contactAddress;
	}

	public Point getContactAddressLocation() {
		return contactAddressLocation;
	}

	public void setContactAddressLocation(Point contactAddressLocation) {
		this.contactAddressLocation = contactAddressLocation;
	}

	public Double getContactAddressLon() {
		return contactAddressLon;
	}

	public void setContactAddressLon(Double contactAddressLon) {
		this.contactAddressLon = contactAddressLon;
	}

	public Double getContactAddressLat() {
		return contactAddressLat;
	}

	public void setContactAddressLat(Double contactAddressLat) {
		this.contactAddressLat = contactAddressLat;
	}

	public String getActivityAddress() {
		return activityAddress;
	}

	public void setActivityAddress(String activityAddress) {
		this.activityAddress = activityAddress;
	}
	
	@JSON(serialize=false)
	public Point getActivityAddressLocation() {
		return activityAddressLocation;
	}

	public void setActivityAddressLocation(Point activityAddressLocation) {
		this.activityAddressLocation = activityAddressLocation;
	}

	public Double getActivityAddressLon() {
		return activityAddressLon;
	}

	public void setActivityAddressLon(Double activityAddressLon) {
		this.activityAddressLon = activityAddressLon;
	}

	public Double getActivityAddressLat() {
		return activityAddressLat;
	}

	public void setActivityAddressLat(Double activityAddressLat) {
		this.activityAddressLat = activityAddressLat;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public Integer getJoinCount() {
		return joinCount;
	}

	public void setJoinCount(Integer joinCount) {
		this.joinCount = joinCount;
	}

	public Integer getJoinLimitCount() {
		return joinLimitCount;
	}

	public void setJoinLimitCount(Integer joinLimitCount) {
		this.joinLimitCount = joinLimitCount;
	}

	public String getProvinceId() {
		return provinceId;
	}

	public void setProvinceId(String provinceId) {
		this.provinceId = provinceId;
	}

	public String getCityId() {
		return cityId;
	}

	public void setCityId(String cityId) {
		this.cityId = cityId;
	}

	public String getAreaId() {
		return areaId;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	public String getStreetId() {
		return streetId;
	}

	public void setStreetId(String streetId) {
		this.streetId = streetId;
	}
	
	/**活动详情提示*/
	@Transient 
	public String getDetailTips(){
		String introTips = "";
		if(StringUtils.isNotBlank(this.detail)){
			introTips = StringUtil.replaceToHtmlQuot(this.detail);
		}
		return introTips;
	}
	
	/**活动封面图片地址*/
	@Transient
	public String getCoverPicIp() {
		String coverPicIp="";
		if (this.coverPic!=null) {
			coverPicIp = StringUtil.getImageTips(this.coverPic.getId());
		}
		return coverPicIp;
		
	}
	
	@Transient
	/**获取活动图集链接*/
	public String getPicLink() {
		String picLink = "<a href=\"javascript:openAdPicsTab('" + super.getId() + "');\" style=\"color:blue;\">图集链接</a>";
		return picLink;
	}
	
	
	@Transient
	public String getIsAdultRecordDesc(){
		String isAdultRecordDesc = "";
		if(IActivityService.IS_RECORD.equals(this.isAdultRecord)) {
			isAdultRecordDesc = "记数";
		} else {
			isAdultRecordDesc = "不记数";
		}
		return isAdultRecordDesc;
	}
	
}
